package com.lcxw.hxzbapi.tencentim.common;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.Random;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RobotsUtils {


    public static final String MSG_WELCOME = "welcome";

    public static final String MSG_WELCOME_ANIMATE = "welcome_animate";

    public static final String MSG_NORMAL = "normal";

    public static final String VIP = "vip";
    public static final String LEVEL = "level";
    public static final String RICH = "rich";


    /**
     * 构造imBody消息的方法
     */
    public JSONObject generateImCustomMsg(String action, String msg, String roomId) {
        JSONObject imBody = new JSONObject();
        JSONArray msgBody = new JSONArray();
        imBody.put("GroupId", roomId);
        imBody.put("Random", new Random().nextInt(10000000));
        JSONObject msgCustomElem = new JSONObject();
        msgCustomElem.put("MsgType", "TIMCustomElem");

        JSONObject msgContentObj = new JSONObject();
        msgContentObj.put("Data", action);
        msgContentObj.put("Ext", msg);
        msgCustomElem.put("MsgContent", msgContentObj);

        msgBody.add(msgCustomElem);
        imBody.put("MsgBody", msgBody);

        return imBody;

    }

    public String getMsgWelcome(String nickName) {
        JSONObject welcome = new JSONObject();
        welcome.put("type", MSG_WELCOME);
        welcome.put("nickName", nickName);
        welcome.put("content", "进入聊天室");
        welcome.put("role", "USER");
        return welcome.toJSONString();

    }

    public String getMsgWelcomeAnimate(String nickName, String faceUrl, int richLevel,
        String vipPicUrl,
        String duanweiPicUrl, String richPicUrl) {
        JSONObject welcome = new JSONObject();
        welcome.put("type", MSG_WELCOME_ANIMATE);
        welcome.put("nickName", nickName);
        welcome.put("faceUrl", faceUrl);
        welcome.put("RICH_LEVEL", richLevel);
        welcome.put(VIP, vipPicUrl);
        welcome.put(LEVEL, duanweiPicUrl);
        welcome.put(RICH, richPicUrl);
        return welcome.toJSONString();
    }

    public String getMsgNormal(String nickName, String content, String vipPicUrl,
        String duanweiPicUrl, String richPicUrl) {
        JSONObject normal = new JSONObject();
        normal.put("type", MSG_NORMAL);
        normal.put("nickName", nickName);
        normal.put("content", content);
        normal.put(VIP, vipPicUrl);
        normal.put(LEVEL, duanweiPicUrl);
        normal.put(RICH, richPicUrl);
        return normal.toJSONString();
    }

}
